package com.loopy.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;

public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      /*  System.out.println("");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter writer = response.getWriter();
        writer.print("<h1>登陆成功</h1>");
        writer.flush();
        writer.close();*/
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        System.out.println("");
        /*输出一句话返回给浏览器
        * 1.通过response获取流PrintWriter,可以给浏览器恢复数据
        * 2.为了让浏览器显示中文，需要告诉浏览器，我们的编码是utf-8
        * 3.setContentType给会送数据设置编码，text/html是MIME,即告诉浏览器返回的数据是text类型的html格式数据[MIME类型]
        * */
        //System.out.println(10/0);
       //response.sendRedirect("/ServletHomework/http.html");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter writer = response.getWriter();
        writer.print("<h1>登陆成功</h1>");
        //把缓存数据刷出去
        writer.flush();
        //关闭流，及时释放资源
        writer.close();
    }
}
